package com.example.controller;

import com.example.pojo.CodeTale;
import com.example.service.MemcachedCodeService;
import com.example.service.impl.MemcachedCodeServiceImpl;
import com.example.service.impl.SmsCodeServiceImpl;
import net.rubyeye.xmemcached.exception.MemcachedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeoutException;

@RestController
@RequestMapping("xmem")
public class XMemcachedController {
    @Autowired
    private MemcachedCodeServiceImpl memcachedCodeService;

    @GetMapping("/sendCode")
    public String sendCode(String tela) throws InterruptedException, TimeoutException, MemcachedException {
        String code = memcachedCodeService.sendUserCode(tela);
        return code;
    }

    @PostMapping("/checkCode")
    public boolean checkCode(CodeTale codeTale) throws InterruptedException, TimeoutException, MemcachedException {
        boolean b = memcachedCodeService.checkCode(codeTale);
        return b;
    }
}
